package com.doudoukeji.service.Activity.order;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.doudoukeji.service.Activity.order.orderdetail.OrderDetailsActivity;
import com.doudoukeji.service.R;
import com.sanhai.android.service.http.Response;
import com.sanhai.android.util.TimeUitl;
import com.sanhai.android.util.Util;

import java.util.List;

/**
 * @version 2.0
 * @类描述： 订单列表
 * @项目名称：ddgh
 * @类名称： OrderListActivity
 * @包名称： com.doudoukeji.service.Activity.order
 * @创建人：张强 boy
 * @创建时间：2016/3/9 13:52
 * @修改人：
 * @修改时间：2016/3/9 13:52
 * @修改备注： new parent class(用一句话描述修改了什么)
 */

public class MyOrderAdapter extends BaseAdapter {
    private Context context;
    private List<OrderListBean> infos;

    public MyOrderAdapter(Context context, List<OrderListBean> infos) {
        this.context = context;
        this.infos = infos;
    }

    @Override
    public int getCount() {
        return infos.size();
    }

    @Override
    public Object getItem(int position) {
        return infos.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public class ViewHolder {
        TextView tv_hospital;
        TextView tv_state;
        TextView tv_time;
        TextView tv_data;
        TextView tv_serviceproject;
        TextView tv_reward_money;
        TextView tv_order_needdescribe;
        TextView tv_more;
    }

    @Override
    public View getView(final int position, final View convertView, ViewGroup parent) {
        View view;
        final ViewHolder holder;
        if (convertView != null) {
            view = convertView;
            holder = (ViewHolder) view.getTag();
        } else {
            view = View.inflate(context, R.layout.item_historyorder, null);
            holder = new ViewHolder();
            holder.tv_hospital = (TextView) view.findViewById(R.id.tv_hospital);
            holder.tv_time = (TextView) view.findViewById(R.id.tv_time);
            holder.tv_data = (TextView) view.findViewById(R.id.tv_data);
            holder.tv_serviceproject = (TextView) view.findViewById(R.id.tv_serviceproject);
            holder.tv_reward_money = (TextView) view.findViewById(R.id.tv_reward_money);
            holder.tv_order_needdescribe = (TextView) view.findViewById(R.id.tv_order_needdescribe);
            holder.tv_more = (TextView) view.findViewById(R.id.tv_more);


            view.setTag(holder);
        }

        OrderListBean textbean = new OrderListBean();
        if (infos != null) {
            textbean = infos.get(position);
        }

        if (textbean.getCreateDate() != null) {
            holder.tv_time.setText(TimeUitl.getDayStr(textbean.getCreateDate()));
        } else {
            holder.tv_time.setText("");
        }
        if (textbean.getHospital() != null) {
            holder.tv_hospital.setText(textbean.getHospital());
        } else {
            holder.tv_hospital.setText("");
        }

        if (textbean.getService() != null) {
            holder.tv_serviceproject.setText(textbean.getService());
        } else {
            holder.tv_serviceproject.setText("");
        }
        if (textbean.getOrderDate() != null) {
            holder.tv_data.setText(textbean.getOrderDate());
        } else {
            holder.tv_data.setText("");
        }
        if (textbean.getMoney() != null) {
            holder.tv_reward_money.setText("￥"+textbean.getMoney());
        } else {
            holder.tv_reward_money.setText("");
        }

        if (textbean.getDescr() != null) {
            holder.tv_order_needdescribe.setText(textbean.getDescr());
        } else {
            holder.tv_order_needdescribe.setText("");
        }

        final OrderListBean finalTextbean = textbean;
        holder.tv_more.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, OrderDetailsActivity.class);
                intent.putExtra("orderid", finalTextbean.getId());
                ((OrderListActivity)context).startActivityForResult(intent,1002);
            }
        });


        view.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
//				Intent intent = new Intent(context,
//						MyOrderDetailsActivity.class);
//				((OrderListActivity)context).startActivity(intent);
            }
        });

        return view;
    }

}
